
using System.Web.UI.HtmlControls;
using System;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;
using System.Collections;
using System.Web.UI;
using System.Web;


using System.IO;
using System.Text;
using com.ddsc.common;
//using com.ddsc.database;
using DDSC.OracleADO;
using com.ddsc.utility;
using log4net;
using log4net.Config;



namespace smasb2b
{
    public class CTMD0061 : BasePage
    {
        #region  Web Form 設計工具產生的程式碼

        //此為 Web Form 設計工具所需的呼叫。
        [System.Diagnostics.DebuggerStepThrough()]
        private void InitializeComponent()
        {
            this.ID = "CTMD0061";

        }
        protected System.Web.UI.WebControls.Label lblCTMD0060;
        protected ddscControlLibrary.ClientButtonCtrl btnHELP;
        protected ddscControlLibrary.ClientButtonCtrl btnEXIT;
        protected System.Web.UI.WebControls.Label lblSHEET_NO;
        protected ddscControlLibrary.InputBoxCtrl txtSHEET_NO;
        protected System.Web.UI.WebControls.Label lblIN_OUT_DATE;
        protected ddscControlLibrary.DateCtrl txtIN_OUT_DATE;
        protected System.Web.UI.WebControls.Label lblSTORE_NO;
        protected ddscControlLibrary.InputBoxCtrl txtSTORE_NO;
        protected System.Web.UI.WebControls.Label lblREF_STORE;
        protected ddscControlLibrary.InputBoxCtrl txtREF_STORE;
        protected System.Web.UI.WebControls.Label lblCTM_APPLY_NO;
        protected ddscControlLibrary.InputBoxCtrl txtCTM_APPLY_NO;
        protected System.Web.UI.WebControls.Label lblIN_OUT;
        protected ddscControlLibrary.InputBoxCtrl txtIN_OUT;
        protected System.Web.UI.WebControls.Label lblTRANS_NO;
        protected ddscControlLibrary.InputBoxCtrl txtTRANS_NO;
        protected System.Web.UI.WebControls.Label lblExecUserId;
        protected ddscControlLibrary.InputBoxCtrl txtUPD_ID;
        protected System.Web.UI.WebControls.Label lblExecDate;
        protected ddscControlLibrary.InputBoxCtrl txtUPD_DATE;
        protected System.Web.UI.WebControls.Label lblExecTime;
        protected ddscControlLibrary.InputBoxCtrl txtUPD_TIME;
        protected System.Web.UI.WebControls.Label lblSEQ;
        protected System.Web.UI.WebControls.Label lblORIGINAL_CODE;
        protected System.Web.UI.WebControls.Label lblCODE;
        protected System.Web.UI.WebControls.Label lblORIGINAL_QTY;
        protected System.Web.UI.WebControls.Label lblTRANS_QTY;
        protected System.Web.UI.WebControls.Label lblORIGINAL_NO;
        protected System.Web.UI.WebControls.Label lblORIGINAL_DATE;
        protected System.Web.UI.WebControls.Label lblREMARK;
        protected ddscControlLibrary.ClientButtonCtrl btnADDROW;
        protected System.Web.UI.HtmlControls.HtmlTable DetailTitle;
        protected System.Web.UI.HtmlControls.HtmlTable DetailTable;

        //注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
        //請勿刪除或移動它。
        private System.Object designerPlaceholderDeclaration;

        private void Page_Init(System.Object sender, System.EventArgs e)
        {
            //CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
            //請勿使用程式碼編輯器進行修改。
            InitializeComponent();
        }

        #endregion

        public CTMD0061()
        {
            log4net.Config.DOMConfigurator.Configure(new System.IO.FileInfo("log4netAppender.xml"));
        }
        StringBuilder sb = new StringBuilder();
        StringBuilder sb1 = new StringBuilder();
        ///*
        //     公用變數宣告區
        //*/
        Array ArrM;

        int rowcount;
        DataBase DataBase = new DataBase();
        private void Page_Load(System.Object sender, System.EventArgs e)
		{
			//在這裡放置使用者程式碼以初始化網頁
			try
			{
				
				string SHEET_NO = "";
				string STORE_NO = "";
				if (this.Request["SHEET_NO"] != null)
				{
					SHEET_NO = this.Request["SHEET_NO"].ToString().Trim();
				}
				else
				{
					SHEET_NO = this.Request["SHEET_NO1"].ToString().Trim();
				}
				if (this.Request["STORE_NO"] != null)
				{
					STORE_NO = this.Request["STORE_NO"].ToString().Trim();
				}
				else
				{
					STORE_NO = this.Request["STORE1"].ToString().Trim();
				}
				//至db 查詢該筆資料
				sb.Append("SELECT A.SHEET_NO,A.IN_OUT_DATE,A.STORE_NO,A.REF_STORE,A.APPLY_NO,A.TRANS_NO,A.IN_OUT,A.UPD_ID,A.UPD_DATE,A.UPD_TIME ");
				sb.Append(",B.SEQ,B.ORIGINAL_CODE,B.CODE,B.ORIGINAL_QTY,B.TRANS_QTY,B.ORIGINAL_NO,B.ORIGINAL_DATE,B.REMARK ");
				sb.Append("FROM CTM_CUSTOMS_TRANS_MASTER A,CTM_CUSTOMS_TRANS_DETAILS B ");

                //Tony : 1.修改SQL語法使用參數，不組字串
				//sb.Append("WHERE A.SHEET_NO=B.SHEET_NO AND A.STORE_NO=B.STORE_NO AND A.SHEET_NO=\'" + SHEET_NO + "\' AND A.STORE_NO=\'" + STORE_NO + "\' ORDER BY B.SEQ");
                sb.Append("WHERE A.SHEET_NO=B.SHEET_NO AND A.STORE_NO=B.STORE_NO AND A.SHEET_NO=:SHEET_NO AND A.STORE_NO=:STORE_NO ORDER BY B.SEQ");

                //Tony : 2.設定動態參數物件
                ArrayList m_arrParam = new ArrayList();
                dbAccess dba = new dbAccess();
                m_arrParam.Add(dba.GetOracleParam(":SHEET_NO", SHEET_NO));
                m_arrParam.Add(dba.GetOracleParam(":STORE_NO", STORE_NO));

                //Tony : 3.修改執行方法Overload
                //DataSet ds = DataBase.Query_CLASS(sb);
                DataSet ds = DataBase.Query_CLASS(sb,m_arrParam);
				
				if (!(ds == null) && ds.Tables[0].Rows[0]["ReturnCode"] != "100" && ds.Tables[0].Rows[0]["ReturnCode"] != "999")
				{
					this.txtSHEET_NO.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["SHEET_NO"].ToString());
					this.txtIN_OUT_DATE.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["IN_OUT_DATE"].ToString());
					this.txtSTORE_NO.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["STORE_NO"].ToString());
					this.txtREF_STORE.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["REF_STORE"].ToString());
					this.txtCTM_APPLY_NO.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["APPLY_NO"].ToString());
					this.txtTRANS_NO.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["TRANS_NO"].ToString());
					this.txtIN_OUT.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["IN_OUT"].ToString());
					this.txtUPD_ID.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["UPD_ID"].ToString());
					this.txtUPD_DATE.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["UPD_DATE"].ToString());
					this.txtUPD_TIME.Text = System.Convert.ToString(ds.Tables[1].Rows[0]["UPD_TIME"].ToString());
					//將此筆資料則顯示於畫面
					int i = 0;
					for (i = 0; i <= ds.Tables[1].Rows.Count - 1; i++)
					{
						string SEQ = System.Convert.ToString(ds.Tables[1].Rows[i]["SEQ"].ToString());
						string ORIGINAL_CODE = System.Convert.ToString(ds.Tables[1].Rows[i]["ORIGINAL_CODE"].ToString());
						string CODE = System.Convert.ToString(ds.Tables[1].Rows[i]["CODE"].ToString());
						string ORIGINAL_QTY = System.Convert.ToString(Math.Round(System.Convert.ToDouble(ds.Tables[1].Rows[i]["ORIGINAL_QTY"]), 0).ToString());
						string TRANS_QTY = System.Convert.ToString(Math.Round(System.Convert.ToDouble(ds.Tables[1].Rows[i]["TRANS_QTY"]), 0).ToString());
						string ORIGINAL_NO = System.Convert.ToString(ds.Tables[1].Rows[i]["ORIGINAL_NO"].ToString());
						string ORIGINAL_DATE = System.Convert.ToString(ds.Tables[1].Rows[i]["ORIGINAL_DATE"].ToString());
						string REMARK = System.Convert.ToString(ds.Tables[1].Rows[i]["REMARK"].ToString());
						AddDetailRow("", i.ToString(), "I", false, SEQ, ORIGINAL_CODE, CODE, ORIGINAL_QTY, TRANS_QTY, ORIGINAL_NO, ORIGINAL_DATE, REMARK);
					}
				}
				else
				{
					//資料已不存在
					this.RegisterStartupScript("Result", "<script language=\"javascript\"> alert(\'此筆資料已被刪除或已送審，請重新選擇！\');window.returnValue = true; this.close(); </script>");
					return;
				}
				
			}
			catch (Exception ex)
			{
				showException(ex.Message);
			}
		}
        public void AddDetailRow(string type, string rows, string M, bool chkStatus, string SEQ, string ORIGINAL_CODE, string CODE, string ORIGINAL_QTY, string TRANS_QTY, string ORIGINAL_NO, string ORIGINAL_DATE, string REMARK)
        {
            HtmlTableRow tr = new HtmlTableRow();
            HtmlTableCell td = default(HtmlTableCell);
            int i = 0;
            int j = 0;
            int rowcount = 0;
            bool chk;
            string Method;
            string Html;
            try
            {
                while (j < 8)
                {
                    switch (j)
                    {
                        case 0:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtSEQ", "5", SEQ, false, "", "", true, "number", "", "txtSEQ", ""));
                            tr.Cells.Add(td);
                            break;
                        case 1:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtORIGINAL_CODE", "5", ORIGINAL_CODE, false, "", "", true, "text", "", "txtORIGINAL_CODE", ""));
                            tr.Cells.Add(td);
                            break;
                        case 2:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtCODE", "5", CODE, false, "", "", true, "text", "", "txtCODE", ""));
                            tr.Cells.Add(td);
                            break;
                        case 3:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtORIGINAL_QTY", "5", ORIGINAL_QTY, false, "", "", true, "number", "", "txtORIGINAL_QTY", ""));
                            tr.Cells.Add(td);
                            break;
                        case 4:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtTRANS_QTY", "5", TRANS_QTY, false, "", "", true, "number", "", "txtTRANS_QTY", ""));
                            tr.Cells.Add(td);
                            break;
                        case 5:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtORIGINAL_NO", "5", ORIGINAL_NO, false, "", "", true, "text", "", "txtORIGINAL_NO", ""));
                            tr.Cells.Add(td);
                            break;
                        case 6:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtORIGINAL_DATE", "5", ORIGINAL_DATE, false, "", "", true, "text", "", "txtORIGINAL_DATE", ""));
                            tr.Cells.Add(td);
                            break;
                        case 7:
                            td = CreareHtmlCell();
                            td.Style.Add("WIDTH", System.Convert.ToString(DetailTitle.Rows[0].Cells[j].Style["WIDTH"]));
                            td.InnerHtml = System.Convert.ToString(CreaterInnerHTML("input", "txtREMARK", "5", REMARK, false, "", "", true, "text", "", "txtREMARK", ""));
                            tr.Cells.Add(td);
                            break;
                    }
                    j++;
                }
                DetailTable.Rows.Add(tr);
            }
            catch (Exception ex)
            {
                showException(ex.Message);
            }
        }

    }

}
